package com.ztgf.user.api.cms;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.shopping.models.dto.shop.ShopInfoDTO;
import com.ztgf.user.models.bo.UserLoginListBO;
import com.ztgf.user.models.dto.UserInfoDTO;
import com.ztgf.user.models.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.ztgf.user.models.service.IUserLoginService;
import com.ztgf.user.models.bo.UserLoginSaveBO;
import com.ztgf.user.models.bo.UserLoginBO;
import com.ztgf.user.models.dto.UserLoginDTO;

/**
 * 用户登录表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-28 17:42:53
 */

@RestController
@RequestMapping("/cms/userLogin")
@Slf4j
@Api(value = "UserLoginController",tags = "用户登录表接口")
public class UserLoginController {

    @DubboReference
    private IUserLoginService userLoginService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<UserLoginDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        UserLoginDTO dto = userLoginService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "用户登录表列表",notes = "用户登录表列表")
    @PostMapping("/queryPageList")
    public Result<Page<UserLoginDTO>> queryPageList(UserLoginListBO bo){
        Wrapper<UserLoginDTO> wrapper = new EntityWrapper<>();

        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<UserLoginDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = userLoginService.selectPage(page, wrapper);

        return new Result<>(page);
    }

    @ApiOperation(value = "根据店铺ID，店铺类型。获取店铺主账号信息",notes = "根据店铺ID，店铺类型。获取店铺主账号信息")
    @PostMapping("/queryPageListByShop")
    public Result<ArrayList<UserLoginVO>> queryPageListByShop(Long shopId, Integer type){
        ArrayList<UserLoginVO> userLoginVOArrayList = userLoginService.queryPageListByShop(shopId, type);

        return new Result<>(userLoginVOArrayList);
    }
}
